#import "RNPrintListContainerCell.h"
#import "RNConstants.h"

static NSUInteger const titlePadding = 5;
static NSUInteger const titleLeftPadding = 0;

@implementation RNPrintListContainerCell

@synthesize titleAttributes = titleAttributes_;

-(id)initTextCell:(NSString *)title {
    if (!(self = [super initTextCell:title]))
        return nil;
    
    NSMutableDictionary *attributes = [NSMutableDictionary dictionary];
    [attributes setValue:[NSFont fontWithName:@"Palatino-Bold" size:13.0f] forKey:NSFontAttributeName];
    [attributes setValue:[NSNumber numberWithInteger:NSUnderlineStyleSingle | NSUnderlinePatternSolid] forKey:NSUnderlineStyleAttributeName];
    [self setTitleAttributes:attributes];
    
    return self;
}

-(void)setObjectValue:(id)obj {
    if (![obj isKindOfClass:[NSDictionary class]])
        return;
    [super setObjectValue:[obj valueForKey:RNTitleKey]];
}

-(void)drawWithFrame:(NSRect)cellFrame inView:(NSView *)controlView {
//    NSRect titleRect = [self titleRectForBounds:cellFrame];
//    NSRect frameRect = cellFrame;
//    frameRect.size.height = NSHeight(titleRect) + 4.0f;
//    frameRect.origin.y = NSMinY(titleRect) - 2.0f;
//    NSBezierPath *framePath = [NSBezierPath bezierPathWithRect:frameRect];
//    [[NSColor blackColor] setStroke];
//    [[NSColor colorWithCalibratedWhite:0.0f alpha:0.2f] setFill];
//    [framePath stroke];
//    [framePath fill];
    NSAttributedString *title = [[NSAttributedString alloc] initWithString:[self stringValue] attributes:[self titleAttributes]];
    [title drawInRect:[self titleRectForBounds:cellFrame]];
}

-(NSRect)titleRectForBounds:(NSRect)cellFrame {
    NSAttributedString *title = [[NSAttributedString alloc] initWithString:[self stringValue] attributes:[self titleAttributes]];
    NSSize titleSize = [title size];
    NSRect titleRect = NSMakeRect(NSMinX(cellFrame) + titleLeftPadding, NSMinY(cellFrame) + NSHeight(cellFrame) - titleSize.height - titlePadding, NSWidth(cellFrame), titleSize.height);
    return titleRect;
}

@end
